Skip to content

TOC-Pumping Lemma

Pumping Lemma

[!abstract]+ Lemma (Pumping Lemma) If A is a regular language, then there is a positive constant p such that every string wA of length at least p can be written as w=xyz satisfying the following conditions

  • for each i0,xyizA
  • |y|>0, and
  • |xy|p.

p is the pumping length.

Instead of proving the lemma formally, let's try to understand it.

Assume A is regular and N is the NFA which recognizes A. Let s be the number of states in N.

Assume w in A of length |w|>s.

To accept w, N goes through a sequence of states q0,q1,,qf

By pigeonhole principle, some states qx appears multiple times in the sequence.

Assuming w=xyz, the sequence of states can be

q0,,qxto accept x,qx,,qxto accept y,,qfto accept z

Then, it's trivial that xz, xyz, xyyz, are all in A.

The pumping lemma is used to prove a language is not regular.

Proof language is not regular

To prove the language A is not regular (ByContradiction)

  • Assume that A is regular.
  • Construct a string wA of length |w|p.
  • Show that no matter how w is split into xyz, there is always an i such that xyizA (contradiction).

Proof Example

[!abstract]+ Theorem L={0n1nfor some natural number n} is not regular.

Proof:

Assume L is regular. Let w=0p1p, which is a string in L. By the pumping lemma, w is in the form xyz. The substring y can be of the following three cases.

  1. If y only consists of 0's, then xyyz (pump y one more time) has more 0's than 1's. Thus, xyyzL.

  2. If y only consists of 1's, same as case 1.

  3. If y has both 0's and 1's, then 0's and 1's in xyyz are intersecting with each other, which is not in the form of 0011. Thus, xyyzL.

In summary, w can never be split into xyz such that xyizL for all i. Thus, L is not regular.

Here are some notes.

The pumping length p depends on the machine. Different machines have different pumping length.

But the pumping lemma is "machine independent". Thus you cannot assume the value of p.

The condition |y|>0 ensures that the substring being pumped is not empty. Otherwise, xyiz=xyz=xz

The condition |xy|p ensures that y always can be pumped by a machine.

The pumping lemma is only a necessary condition for regular. It is not a sufficient condition. In other words, if you cannot find a w or such w does not exist to accomplish the proof, you CANNOT say the language is regular.

Pumping lemma proof example

L3={ann2 and n is a prime number}.

Answer: Not regular.

Proof:

Assume L3 is regular. Consider the string ac, where c is a prime number and c>p (where p is a constant from the pumping lemma). By definition, acL3.

Since prime numbers are infinite, ac is constructible for some c>p. (This point is crucial because, if ac were not constructible, the proof could not proceed.)

By the pumping lemma, ac can be split into three substrings xyz, where:

  • |xy|p,
  • |y|>0,
  • xyizL3 for all i0.

Here, y consists of only a's. Assume |y|=d. Then |xz|=cd.

Now, consider the string xyc+1z (i.e., xyiz for i=c+1):

  • Its length is |xz|+(c+1)|y|=(cd)+(c+1)d=c(d+1).

However, c(d+1) is not a prime number, because c is a prime number, and d+1 (where d1) is an integer greater than 1.

Thus, xyc+1zL3, which contradicts the pumping lemma. Therefore, L3 is not regular.

L4={ann is not a prime number}.

Answer: Not regular.

Proof (Sketch):

We can express L4 as:

L4=Σ(L3{ε,a})=L3{ε,a}.
  • Here, L3={ann is a prime number}, and {ε,a} are regular languages.
  • Regular languages are closed under set union and complement.

If L4 were regular, then L3 would also be regular (by closure properties of regular languages). However, this contradicts the result from L3, where L3 was proven to be not regular. Thus, L4 is not regular.

L6=L3.

Answer: Regular. In fact, L6=Σ{a}.

Proof:

Consider ai:

  1. Case 0: If i=0, then a0=εL30.

  2. Case 1: If i is a prime, then aiL3.

  3. Case 2: If i is composite, then i=p1c1×p2c2××pncn, where each pj is a prime and cj is a positive integer constant.

    • Next, apjcjL3 for all j.
    • Thus, aiL3c1L3c2L3cn.

Thus, aiΣ.

L7={anbnn1}{anbmn1,m1}

Answer: Regular.

  • {anbnn1}{anbmn1,m1}.
  • {anbmn1,m1} is regular.

L8={anbnn1}{anbn+2n1}

Answer: Not regular.

Proof (Sketch):

  • Consider the string apbp.
  • Then, xy2zL8.

Pumping Lemma for Context-Free Language

[!abstract]+ Lemma (Pumping Lemma for Context-Free Language) If A is a context-free language, then there is a positive constant p (pumping length) such that every string sA of length at least p can be written as s=wvxyz satisfying the following conditions:

  • For each i0,wvixyizA,
  • |vy|>0, and
  • |vxy|p

Assume L is context-free. Let s=0p1p#0p1p, which is a string in L. By the pumping lemma, s=wvxyz. Then, we have two cases.

|vy|>0|vxy|p

  • Case 1

vxy before the #

α=wv2xy2z has more symbols before # then after.

  • Case 2

vxy before the #

α=wv2xy2z=0..01...1#0...01...1

more 1's but less 0's